<template>
	<view class="groupactiveinfo">
		<view class="groupactiveinfo_head_img_box" v-if="info.pic">
			<image class="groupactiveinfo_head_img" :src="picUrl+info.pic" mode="widthFix">
			</image>
		</view>
		<view class="groupactiveinfo_title" style="padding: 30rpx;">{{info.title}}</view>
		<view class="f-12 c-999999 ml-15" v-if="info.create_time">{{info.create_time.substr(0,10)}} </view>
		<view class="bbs_user_info_box">
			<view class="bbs_user_info">
				<view class="bbs_user_avatar_box" v-if="info.club_logo">
					<image class="avater_img" :src="picUrl+info.club_logo" mode="aspectFill"></image>
				</view>
				<view class="bbs_user_avatar_box" v-else>
					<image class="avater_img" :src="groupinfo.logo?picUrl+groupinfo.logo:onlinePic+'avatar.png'"
						mode="aspectFill"></image>
				</view>
				<view class="ml-10 flex-1">
					<view class="f-15 f-w">{{info.club_title?info.club_title:groupinfo.title}}</view>
					<!-- <view class="c-gray f-12">斯巴鲁北京车友会管理员</view> -->
				</view>
				<image class="join_btn" :src="onlinePic+'join_btn.png'"></image>
			</view>
		</view>
		<view class="pd-30">
			<view class="groupactiveinfo_content_cell" v-for="(item,index) in info.content" :key="index">
				<image v-for="itemi in item.images" :key="itemi" class="groupactiveinfo_content_img" :src="picUrl+itemi"
					mode="widthFix">
				</image>
				<view class="groupactiveinfo_content_text">
					<text>{{item.text}}</text>
				</view>
			</view>
		</view>
		<view class="groupactive_form_box">
			<view class="group_active_xiong_box">
				<view class="group_active_xiong">
					<image class="xiong_6" :src="onlinePic+'xiong.png'"></image>
				</view>
				<view class="racy_box">
					<view class="racy_text">活动报名</view>
					<view class="racy_line_box"></view>
				</view>
			</view>
			<view class="groupmanage_input_box">
				<view class="mr-5">姓名</view>
			</view>
			<view class="groupmanage_input_box">
				<view class="mr-5">电话</view>
			</view>
			<view class="groupmanage_input_box" v-if="info.is_pic==1">
				<view class="mr-5">上传爱车靓照</view>
				<view class="cars_block_box">
					<uni-icons color="#00A0DC" type="plus-filled" size="40"></uni-icons>
				</view>
			</view>
			<view v-if="info.is_pet==1" class="groupmanage_input_box">
				<view class="mr-5 display_flex">是否带宠物
					<view class="display_flex ml-20" @click="changePet(1)">
						<uni-icons v-if="is_pet==1" type="checkbox-filled" size="20" color="#191919"></uni-icons>
						<uni-icons v-else type="circle" size="20" color="#191919"></uni-icons>
						<span>是</span>
					</view>
					<view class="display_flex ml-25" @click="changePet(2)">
						<uni-icons v-if="is_pet==2" type="checkbox-filled" size="20" color="#191919"></uni-icons>
						<uni-icons v-else type="circle" size="20" color="#191919"></uni-icons>
						<span>否</span>
					</view>
				</view>
			</view>
			<view v-if="is_pet==1" class="groupmanage_input_box">
				<view class="display_flex">
					<view class="mr-5">宠物类型</view>
					<uni-data-select class="flex-1 f-12" v-model="pet_type" :localdata="petTypelist"
						:clear="false"></uni-data-select>
				</view>
			</view>
			<view v-if="is_pet==1" class="groupmanage_input_box">
				<view class="display_flex">
					<view class="mr-5">宠物数量</view>
					<uni-data-select class="flex-1 f-12" v-model="pet_num" :localdata="petNumlist"
						:clear="false"></uni-data-select>
				</view>
			</view>
			<view v-if="info.is_child==1" class="groupmanage_input_box">
				<view class="mr-5 display_flex">
					是否带儿童
					<view class="display_flex ml-20" @click="changeChild(1)">
						<uni-icons v-if="is_child==1" type="checkbox-filled" size="20" color="#191919"></uni-icons>
						<uni-icons v-else type="circle" size="20" color="#191919"></uni-icons>
						<span>是</span>
					</view>
					<view class="display_flex ml-25" @click="changeChild(2)">
						<uni-icons v-if="is_child==2" type="checkbox-filled" size="20" color="#191919"></uni-icons>
						<uni-icons v-else type="circle" size="20" color="#191919"></uni-icons>
						<span>否</span>
					</view>
				</view>
			</view>
			<view v-if="is_child==1" class="groupmanage_input_box">
				<view class="display_flex">
					<view class="mr-5">年龄</view>
					<uni-data-select class="flex-1 f-12" v-model="child_age" :localdata="childAgelist"
						:clear="false"></uni-data-select>
				</view>
			</view>
			<view v-if="is_child==1" class="groupmanage_input_box">
				<view class="display_flex">
					<view class="mr-5">人数</view>
					<uni-data-select class="flex-1 f-12" v-model="child_num" :localdata="childNumlist"
						:clear="false"></uni-data-select>
				</view>
			</view>
			<view class="next_step_btnd">提交信息</view>
		</view>
		<view class="lineh" v-if="isCheck!=1 || (isCheck==1 && info.huodong_status == 1)"
			:style="'padding-bottom:'+pdbottom+'rpx;'"></view>
		<view class="lineh" v-if="isCheck==1 && (info.huodong_status == 2 || info.huodong_status == 3 || info.huodong_status == 4)"
			:style="'padding-bottom:'+(pdbottom + 40)+'rpx;'"></view>
		<view v-if="isCheck!=1" class="button" @click="submitForm">提交审核</view>
		<view v-if="isCheck==1 && info.huodong_status == 1" class="button trip">SOC审核中</view>
		<view v-if="isCheck==1 && info.huodong_status == 2" class="button h140">
			<view>SOC审核未通过</view>
			<view class="bt-line" @click="openPopup">查看拒绝理由</view>
		</view>
		<view v-if="isCheck==1 && info.huodong_status == 3" class="button h140">
			<view>SOC审核已通过</view>
			<view class="bt-line" @click="submitPush">立即发布</view>
		</view>
		<view v-if="isCheck==1 && info.huodong_status == 4" class="button h140">
			<view>活动已上线</view>
			<view class="bt-line" @click="submitOffline">立即下线</view>
		</view>
		<view v-if="popupImg" class="mask_box"></view>
		<view class="popup_img_box" v-if="popupImg">
			<image class="popup_img" :src="onlinePic+'manage/popup_img.png'" mode="widthFix"></image>
			<view class="popup_trip">{{info.refuse_reason}}</view>
			<view class="popup_sub">
				<view class="sub left" @click="closePopup">关闭弹框</view>
				<view class="sub right" @click="reSub">重新提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		submitAdminGroupActive,
		getAdminGroupActiveInfo,
		submitGroupActivePush,
		getAdminGroupInfo,
		submitGroupActiveOffline
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				popupImg: false,
				isCheck: '',
				club_id: '',
				huodong_id: '',
				info: {
					pic: '',
					club_logo: ''
				},
				groupinfo: {
					logo: ''
				},
				userinfo: uni.getStorageSync('userinfo'),
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				petNumlist: [],
				childNumlist: [],
				childAgelist: [],
				pet_num: '',
				pet_type: '',
				child_num: '',
				child_age: '',
				is_pet: '',
				is_child: '',
				petTypelist: [{
						value: 1,
						text: "狗"
					},
					{
						value: 2,
						text: "猫"
					},
					{
						value: 3,
						text: "其他"
					}
				],
				pdbottom: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets.bottom +
					100 : 100,
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
			if (uni.getStorageSync('userinfo').is_staff == 0) {
				uni.switchTab({
					url: '/pages/index/index'
				})
			} else {
				if (uni.getStorageSync('onload')) {
					this.getAdminGroupActiveInfo()
				}
			}
		},
		onLoad(options) {
			if (uni.getStorageSync('userinfo').is_staff != 0) {
				this.club_id = options.club_id ? options.club_id : ''
				this.isCheck = options.isCheck ? options.isCheck : ''
				this.huodong_id = options.huodong_id ? options.huodong_id : ''
				if (options.isCheck == 1) {
					this.getAdminGroupActiveInfo()
				} else if (options.isCheck == 0) {
					this.getAdminGroupInfo()
				}
			}
			this.info = uni.getStorageSync('activeForm') ? uni.getStorageSync('activeForm') : ''
			this.petNumlist = Array.from({
				length: 5
			}, (_, index) => ({
				value: index + 1, // 从1开始计数  
				text: index + 1 + '只' // 对应的文本  
			}));
			this.childNumlist = Array.from({
				length: 5
			}, (_, index) => ({
				value: index + 1, // 从1开始计数  
				text: index + 1 + '人' // 对应的文本  
			}));
			this.childAgelist = Array.from({
				length: 18
			}, (_, index) => ({
				value: index + 1, // 从1开始计数  
				text: index + 1 + '岁' // 对应的文本  
			}));
		},
		methods: {
			openPopup() {
				this.popupImg = true
			},
			closePopup() {
				this.popupImg = false
			},
			reSub() {
				uni.navigateTo({
					url: '/pages/groupmanage/groupactivepost?club_id=' + this.club_id + '&huodong_id=' + this
						.huodong_id
				})
				this.popupImg = false
			},
			getAdminGroupInfo() {
				getAdminGroupInfo({
					club_id: this.club_id
				}).then(res => {
					if (res.state == 1) {
						this.groupinfo = res.data.info
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getAdminGroupActiveInfo() {
				getAdminGroupActiveInfo({
					huodong_id: this.huodong_id
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
						var params = {
							event_code: '车友会活动管理详情',
							path: 'pages/groupmanage/groupactiveinfo',
							event_id: this.huodong_id,
							title: res.data.info.title,
							source_page: '',
							value: '',
						}
						app.BurialPoint(params)
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			submitForm() {
				var that = this
				uni.showModal({
					content: '确定提交审核吗',
					confirmColor: '#00A0DC',
					success: function(res) {
						if (res.confirm) {
							console.log(that.info);
							that.info.club_id = that.club_id
							if (that.info.huodong_id) {
								var apiurl = 'club/admin-huodong-edit'
							} else {
								var apiurl = 'club/admin-huodong-add'
							}


							submitAdminGroupActive(apiurl, that.info).then(res => {
								if (res.state == 1) {
									uni.showToast({
										title: '提交成功',
										mask: true,
										icon: 'success',
										duration: 1500
									})
									uni.setStorage({
										key: 'onload',
										data: 'true',
										success() {}
									})
									uni.removeStorage({
										key: 'activeForm'
									})
									setTimeout(function() {
										uni.navigateBack({
											delta: 2
										})
										setTimeout(function() {
											that.isSubmit = true
											that.info = {
												pic: '',
											}
										}, 100)
									}, 1000)

								} else {
									uni.showToast({
										title: res.error[0],
										mask: true,
										icon: 'none',
										duration: 1500
									})
								}
							})
							var params = {
								event_code: '车友会活动管理详情',
								path: 'pages/groupmanage/groupactiveinfo',
								event_id: that.info.huodong_id,
								title: that.info.title,
								source_page: '车友会活动管理详情-提交审核',
								value: '',
							}
							app.BurialPoint(params)
						} else if (res.cancel) {
							console.log('用户点击取消');
							that.isSubmit = true
						}
					}
				});
			},
			submitPush() {
				var that = this
				uni.showModal({
					content: '确定要发布此活动吗？',
					confirmText: '发布',
					confirmColor: '#00A0DC',
					success: function(res) {
						if (res.confirm) {
							console.log(that.info);

							submitGroupActivePush({
								huodong_id: that.info.huodong_id
							}).then(res => {
								if (res.state == 1) {
									uni.showToast({
										title: '发布成功',
										mask: true,
										icon: 'success',
										duration: 1500
									})
									uni.setStorage({
										key: 'onload',
										data: 'true',
										success() {}
									})
									setTimeout(function() {
										that.isSubmit = true
										uni.navigateBack({
											delta: 1
										})
									}, 1000)

								} else {
									uni.showToast({
										title: res.error[0],
										mask: true,
										icon: 'none',
										duration: 1500
									})
								}
							})
							var params = {
								event_code: '车友会活动管理详情',
								path: 'pages/groupmanage/groupactiveinfo',
								event_id: that.info.huodong_id,
								title: that.info.title,
								source_page: '车友会活动管理详情-确定发布',
								value: '',
							}
							app.BurialPoint(params)
						} else if (res.cancel) {
							console.log('用户点击取消');
							that.isSubmit = true
						}
					}
				});
			},
			submitOffline() {
				var that = this
				uni.showModal({
					content: '确定要下线此活动吗？',
					confirmText: '下线',
					confirmColor: '#00A0DC',
					success: function(res) {
						if (res.confirm) {
							console.log(that.info);
							submitGroupActiveOffline({
								huodong_id: that.info.huodong_id
							}).then(res => {
								if (res.state == 1) {
									uni.showToast({
										title: '下线成功',
										mask: true,
										icon: 'success',
										duration: 1500
									})
									uni.setStorage({
										key: 'onload',
										data: 'true',
										success() {}
									})
									setTimeout(function() {
										that.isSubmit = true
										uni.navigateBack({
											delta: 1
										})
									}, 1000)

								} else {
									uni.showToast({
										title: res.error[0],
										mask: true,
										icon: 'none',
										duration: 1500
									})
								}
							})
							var params = {
								event_code: '车友会活动管理详情',
								path: 'pages/groupmanage/groupactiveinfo',
								event_id: that.info.huodong_id,
								title: that.info.title,
								source_page: '车友会活动管理详情-确定发布',
								value: '',
							}
							app.BurialPoint(params)
						} else if (res.cancel) {
							console.log('用户点击取消');
							that.isSubmit = true
						}
					}
				});
			},
			changePet(type) {
				this.is_pet = type
			},
			changeChild(type) {
				this.is_child = type
			},
		}
	}
</script>

<style lang="scss">
	.groupactiveinfo {

		.groupactiveinfo_head_img_box {
			width: 100%;
			// height: 50vw;

			.groupactiveinfo_head_img {
				width: 100%;
				// height: 50vw;
			}
		}

		.bbs_user_info_box {
			padding: 30rpx;

			.bbs_user_info {
				display: flex;
				align-items: center;

				.bbs_user_avatar_box {
					width: 90rpx;
					height: 90rpx;
					position: relative;
					border-radius: 8rpx;

					.avater_img {
						width: 90rpx;
						height: 90rpx;
						border-radius: 8rpx;
					}

					.avater_v_icon {
						width: 30rpx;
						height: 30rpx;
						position: absolute;
						right: 10rpx;
						bottom: 0;
						z-index: 1;
					}
				}

				.follow_img {
					width: 95rpx;
					height: 45rpx;
					vertical-align: middle;
				}

				.join_btn {
					width: 135rpx;
					height: 90rpx;
					vertical-align: middle;
				}
			}
		}

		.groupactiveinfo_title {
			font-size: 36rpx;
			font-weight: bold;
			line-height: 50rpx;
		}

		.groupactiveinfo_content_cell {
			font-size: 28rpx;

			.groupactiveinfo_content_img {
				width: 100%;
				vertical-align: middle;
				border-radius: 8rpx;
				margin-top: 20rpx;
			}
			
			.groupactiveinfo_content_img:first-child {
				margin-top: 0rpx;
			}

			.groupactiveinfo_content_text {
				color: #000000;
				margin: 20rpx 0;
				line-height: 48rpx;
			}
		}

		.next_step_btnd {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #000000;
			padding: 25rpx 0;
			margin-top: 30rpx;
			border-radius: 8rpx;
			background-color: #eaeaea;
		}

		.next_step_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 0 0 60rpx 0;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.button {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #00A0DC;
			font-size: 30rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 100rpx;
			z-index: 2;

			&.trip {
				background-color: #E9E9E9;
				color: #666666;
			}

			&.h140 {
				line-height: 40rpx;
				height: 140rpx;
				padding-top: 30rpx;
				box-sizing: border-box;

				.bt-line {
					border-bottom: 2rpx solid #FFFFFF;
					display: inline-block;
				}
			}
		}

		.popup_img_box {
			position: fixed;
			top: 10%;
			left: 60rpx;
			right: 16rpx;
			z-index: 1001;

			.popup_img {
				width: 100%;
				vertical-align: middle;
			}

			.popup_trip {
				padding: 0 150rpx 0 60rpx;
				position: absolute;
				top: 160rpx;
				color: #666666;
				font-size: 28rpx;
			}

			.popup_sub {
				margin-top: 20rpx;
				margin-right: 44rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.sub {
					width: 287rpx;
					height: 80rpx;
					line-height: 80rpx;
					color: #FFFFFF;
					font-size: 36rpx;
					background-color: #00A0DC;
					border-radius: 8rpx;
					text-align: center;


					&.left {
						color: #00A0DC;
						background-color: #FFFFFF;
					}
				}
			}
		}
	}
</style>